﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Subgurim.Controles;
using CounterServerModel;
using CounterServerModel.Authentication;
using System.Collections.Generic;

namespace SmartCounters
{
	public partial class GMapsMonitor : System.Web.UI.Page
	{

		protected void Page_Load(object sender, EventArgs e)
		{
            GMapM.Key = "AIzaSyARmX9FYK0psugZwDZWZNPYdWKYJ6U-Hmc";
            GMapM.enableHookMouseWheelToZoom = true;

            GIcon icoAccunt = new GIcon("Icons/Account.ico");
            GIcon icoFault  = new GIcon("Icons/Fault.ico");

            AccountInfo user;
            InformationReader infoProvider = new InformationReader();
            List<AccountInfo> accounts     = new InformationReader().GetAllAccounts(((MainTemplate)Master).AuthenticatedLoggedInUserCredentials);
            List<Fault> faults             = new InformationReader().GetAllFaults(((MainTemplate)Master).AuthenticatedLoggedInUserCredentials);
            

            GLatLng israel = new GLatLng(31.774469,35.213242);
           
            GMapM.setCenter(israel, 8);

            foreach (AccountInfo account in accounts)
            {
                double lat = account.Latitude;
                double lon = account.Longitude;

                string strtitel = "Information : " + account.City + "  " + account.Street + "  " + account.House + "  Phone number : " + account.Phone;

                GLatLng Gllng = new GLatLng(lat,lon);

                GMarkerOptions GmOptions = new GMarkerOptions();

                GMarker GMker = new GMarker(Gllng, icoAccunt);

                GMker.options.title = strtitel;

                GInfoWindow info = new GInfoWindow(GMker, strtitel, GListener.Event.click);
     
                GMapM.addInfoWindow(info);
                GMapM.addGMarker(GMker);

            }


            foreach (Fault fault in faults)
            {
                user = infoProvider.GetAccountInformation(((MainTemplate)Master).AuthenticatedLoggedInUserCredentials, fault.AccountID);

                double lat = user.Latitude;
                double lon = user.Longitude;


                string strtitel = "Information : " + user.City + "  " + user.Street + "  " + user.House + "  Phone number : " + user.Phone;

                GLatLng Gllng = new GLatLng(lat, lon);

                GMarkerOptions GmOptions = new GMarkerOptions();

                GMarker GMker = new GMarker(Gllng, icoFault);

                GMker.options.title = strtitel;

                GInfoWindow info = new GInfoWindow(GMker, strtitel, GListener.Event.click);
                
                GMapM.addInfoWindow(info);
                GMapM.addGMarker(GMker);
            }

		}
	}
}